home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Cheat II
/
original
/
cheatWindow.c
< prev
next >
Wrap
Text File
|
1995-09-05
|
8KB
|
338 lines
/*****
* cheatWindow.c
*
*
*****/
#include <Processes.h>
#include "cheatWindow.h"
#include "main.h"
#include "ResRefs.h"
#include "cheat.h"
#include "error.h"
#include "cheatwich.h"
#define krefreshrate 60
Rect listRect = {170, 150, 280, 365};
Rect slistRect = {84, 8, 240, 230};
Rect picrect = {4, 4, 36, 36};
WindowPtr cheatWindow, sheetWindow;
Handle ditem[riNumItems], sitem[riSheetItems];
Rect dragRect;
int useColor = false, cheatWindDepth = 1;
ListHandle plist, slist;
ProcessInfoRec InfoRec[maxProcs];
long numProcs = 0;
ProcessSerialNumber usPSN;
// it's an old way to do it, and though Apple doesn't promise to support it,
// I bet they will
static void CheckForColor()
{
SysEnvRec se;
if (SysEnvirons(1, &se) == 0)
if (se.hasColorQD)
useColor = true;
}
// part of following function borrowed from GPS by Glen Lalonde
static void readProcTable(void)
{
ProcessSerialNumber process;
OSErr res;
ProcessInfoRec recTemp;
Boolean same;
process.highLongOfPSN = 0;
process.lowLongOfPSN = kNoProcess;
verify(!GetCurrentProcess(&usPSN));
numProcs = 0;
while( GetNextProcess(&process) == noErr) {
// first make sure this process isn't us, we don't want to cheat on ourselves
res = SameProcess(&process, &usPSN, &same);
if (res || same)
continue; // it is us
InfoRec[numProcs].processInfoLength = sizeof(ProcessInfoRec);
if (!InfoRec[numProcs].processName)
InfoRec[numProcs].processName = (void *)NewPtr(32);
InfoRec[numProcs].processAppSpec = 0;
if ((res = GetProcessInformation(&process, &(InfoRec[numProcs]))) != noErr)
verify(false);
numProcs++;
if (numProcs > maxProcs) break; /* too many to handle */
}
if (numProcs > maxProcs)
numProcs = maxProcs;
}
static void addProcsToList(void)
{
short i;
Cell cell = {0, 0};
(void) LAddRow(numProcs, 0, plist);
for (i=0;i<numProcs;i++) {
cell.v = i;
LSetCell((Ptr) &(InfoRec[i].processName[1]), InfoRec[i].processName[0], cell, plist);
}
}
void refreshProcesses(void)
{
ProcessSerialNumber oldpsn[maxProcs], oldselection;
short i, oldNumProcs, changed, didselect;
static unsigned long lastcall = 0;
Cell cell = {0, 0};
Boolean same;
OSErr res;
if (TickCount() - lastcall < krefreshrate)
return; // hasn't been long enough
lastcall = TickCount();
// first, we save the old numbers
oldNumProcs = numProcs;
for (i=0;i<numProcs;i++)
oldpsn[i] = InfoRec[i].processNumber;
// remember selection in terms of a PSN
if (didselect = LGetSelect(true, &cell, plist))
oldselection = InfoRec[cell.v].processNumber;
// find current process list
readProcTable();
// find if there's a difference
changed = false;
if (numProcs != oldNumProcs)
changed = true;
else
for (i=0;i<numProcs;i++) // check to see if numbers the same
changed |=
(oldpsn[i].highLongOfPSN != InfoRec[i].processNumber.highLongOfPSN) ||
(oldpsn[i].lowLongOfPSN != InfoRec[i].processNumber.lowLongOfPSN);
// now, if things have changed we have to clear old list and make new one
if (changed) {
LDoDraw(false, plist);
LDelRow(0, 0, plist); // remove contents of list
addProcsToList(); // add them again
// reselect old process if there was one selected
if (didselect)
for (i=0;i<numProcs;i++) {
res = SameProcess(&oldselection, &InfoRec[i].processNumber, &same);
cell.v = i;
if (same)
LSetSelect(true, cell, plist);
}
LDoDraw(true, plist);
SetPort(cheatWindow);
InvalRect(&listRect); // so it draws on update
EraseRect(&listRect);
}
}
static void MakeAList(void)
{
Rect dataBounds = {0, 0, 0, 1};
Point cSize = {0, 0};
plist = LNew(&listRect, &dataBounds, cSize, 0, cheatWindow, true, false, false, true);
verify(plist);
readProcTable();
addProcsToList();
}
static void InitCheatSheet(void)
{
Rect dataBounds = {0, 0, 0, 1};
Point cSize = {0, 0};
int i;
Handle h;
Cell cell;
dataBounds.bottom = Count1Resources(kcheatsheettype);
slist = LNew(&slistRect, &dataBounds, cSize, 0, sheetWindow, true, false, false, true);
verify(slist);
cut = (shortcut **) NewHandle(dataBounds.bottom * sizeof(shortcut));
verify(cut);
HLock((Handle) cut);
// get all the shortcuts from the resources
cell.h = 0;
for (i=1;i<=dataBounds.bottom;i++) {
h = Get1IndResource(kcheatsheettype, i);
verify(h);
HLock((Handle) h);
(*cut)[i-1] = **((shortcut **) h); // move the data over
cell.v = i - 1;
// add to list
LSetCell((Ptr) &((*cut)[i-1].title[1]), (*cut)[i-1].title[0], cell, slist);
HUnlock((Handle) h);
ReleaseResource(h);
}
HUnlock((Handle) cut);
gnumcuts = dataBounds.bottom;
}
// futzes with radio boxes
void setSearchSize(short newsize)
{
short i;
gvalsize = newsize;
for (i=0;i<3;i++)
SetCtlValue((ControlHandle) ditem[i+riSizeLong], newsize == i);
}
// futzes with radio boxes
void setFindGameBy(short newval)
{
short i;
ghowfind = newval;
for (i=0;i<2;i++)
SetCtlValue((ControlHandle) ditem[i+riSelecting], ghowfind == i);
}
void SetUpWindow(void)
{
PixMapHandle ppix;
short i, type;
Rect box;
short px, py;
dragRect = screenBits.bounds;
CheckForColor();
// if (useColor)
// cheatWindow = (WindowPtr) NewCWindow(0L, &windowBounds, "\pUntitled", true, noGrowDocProc, (WindowPtr) -1L, true, 0);
// else
// first we put up the cheat sheet, as it's behind
sheetWindow = GetNewDialog(rSheetDialog, 0, (WindowPtr) -1L);
verify(sheetWindow);
py = 50;
px = 491; // desired left position of window
if (px + 258 + 8 > screenBits.bounds.right)
px = screenBits.bounds.right - 258 - 8;
MoveWindow((WindowPtr) sheetWindow, px, py, false);
ShowWindow((WindowPtr) sheetWindow);
// get items in dialog for future reference
for (i=1;i<riSheetItems;i++) {
GetDItem(sheetWindow, i, &type, &sitem[i], &box);
verify(sitem[i]);
}
HiliteControl((ControlHandle) sitem[riExportNew], 255);
HiliteControl((ControlHandle) sitem[riAppendToOld], 255);
HiliteControl((ControlHandle) sitem[riExportAppend], 255);
HiliteControl((ControlHandle) sitem[riOpenCheat], 255);
HiliteControl((ControlHandle) sitem[riRemoveCheat], 255);
HiliteControl((ControlHandle) sitem[riAddCheat], 255);
InitCheatSheet();
cheatWindow = GetNewDialog(rOurDialog, 0, (WindowPtr) -1L);
verify(cheatWindow);
SetPort(cheatWindow);
// get items in dialog for future reference
for (i=1;i<riNumItems;i++) {
GetDItem(cheatWindow, i, &type, &ditem[i], &box);
verify(ditem[i]);
}
setSearchSize(ksizeint);
setFindGameBy(kfindselect);
if (useColor) {
ppix = ((CWindowPtr) cheatWindow)->portPixMap;
verify(ppix);
cheatWindDepth = (**ppix).pixelSize;
if (cheatWindDepth < 4)
useColor = false;
else { // get pixpats etc.
}
}
MakeAList();
}
void DrawFoundPic(void)
{
static CIconHandle sunc = 0, cloudc = 0;
SetPort(cheatWindow);
if (!sunc) { // read from resource file
sunc = GetCIcon(rSunCicn); verify(sunc);
cloudc = GetCIcon(rCloudsCicn); verify(cloudc);
}
if (useColor)
if (gcurposs == 1)
PlotCIcon(&picrect, sunc);
else
PlotCIcon(&picrect, cloudc);
}
// called when the interruptor has done stuff and we need to redraw screen etc
void doclearup(void)
{
Str255 str;
addwichcuts();
// change the text field of the possibilities item
NumToString(gcurposs, str);
SetIText(ditem[riPossibilities], str);
// change the text field of the offset item
if (gcurposs)
NumToString(goffset, str);
else
str[0] = 0; // empty string
SetIText(ditem[riOffset], str);
setSearchSize(gvalsize); // make sure radio buttons correctly highlighted
DrawFoundPic();
fixshortbuttz();
}
void DrawCheatWindow(void)
{
Rect r = listRect;
SetPort(cheatWindow);
InsetRect(&r, -1, -1);
FrameRect(&r);
LUpdate(cheatWindow->visRgn, plist);
DrawFoundPic();
}
void DrawSheetWindow(void)
{
Rect r = slistRect;
SetPort(sheetWindow);
InsetRect(&r, -1, -1);
FrameRect(&r);
LUpdate(sheetWindow->visRgn, slist);
}